﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;

namespace PagesList
{
    public partial class XangMuPage : UserControl
    {
        public XangMuPage()
        {
            InitializeComponent();
            ShowData();
        }

        public void ShowData()
        {
            OleDbCommandBuilder oledbCmdBuilder;
            ds = new DataSet();
            string sql = null;
            
            connection = ConnectManager.GetSystemConnect();
            if (textBox1.Text == "")
            {
                sql = "select jymddh as 检验目的编码,"+
                         " jymdmc 检验目的,"+
                         "jyyq 仪器,"+
                         " (select leibei from f_leibei where leibeidh=mdlb) 专业组,"+
                         "(select gname from t_base_labgroup where gcode=zyz) 架子,"+
                         "jymdsf  牌价,"+
                         "(select mc from xt_bbzl where dh=bbzl) 标本类型,jymdlb,mayodh"+ 
                         " from  xt_jymd  "+
                         "where (sfkz is NULL or sfkz =' ') order by jymddh";
            }
            else
            {
                sql = "select jymddh as 检验目的编码,"+
                         " jymdmc 检验目的,"+
                         "jyyq 仪器,"+
                         " (select leibei from f_leibei where leibeidh=mdlb) 专业组,"+
                         "(select gname from t_base_labgroup where gcode=zyz) 架子,"+
                         "jymdsf  牌价,"+
                         "(select mc from xt_bbzl where dh=bbzl) 标本类型 ,jymdlb,mayodh" + 
                         " from  xt_jymd  "+
                         "where (sfkz is NULL or sfkz =' ') and  jymdmc like '%" + textBox1.Text + "%'";
            }
            try
            {
                oledbAdapter = new OleDbDataAdapter(sql, connection);
                oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
                oledbAdapter.Fill(ds);
                this.dataGridView1.DataSource = ds.Tables[0];

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }


        }

        protected void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
        {
            if (ds == null || oledbAdapter == null)
            {
                return;
            }
            oledbAdapter.Update(ds);
        }

        private OleDbConnection connection;
        private OleDbDataAdapter oledbAdapter;
        private DataSet ds;

        private void XangMuPage_Resize(object sender, EventArgs e)
        {
            this.dataGridView1.Size = this.Size - new System.Drawing.Size(50, 100);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            ShowData();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            ExcelExportTool.DataGridViewToExcel(this.dataGridView1);
        }

        private void button3_Click(object sender, EventArgs e)
        {
   
            OleDbCommandBuilder oledbCmdBuilder;
            ds = new DataSet();
            string sql = null;

            connection = ConnectManager.GetSystemConnect();
                sql = "select jymddh as 检验目的编码," +
                         " jymdmc 检验目的," +
                         "jyyq 仪器," +
                         " (select leibei from f_leibei where leibeidh=mdlb) 专业组," +
                         "(select gname from t_base_labgroup where gcode=zyz) 架子," +
                         "jymdsf  牌价," +
                         "(select mc from xt_bbzl where dh=bbzl) 标本类型,jymdlb,mayodh" +
                         " from  xt_jymd  " +
                         "where jymdlb='MAYO'";
            try
            {
                oledbAdapter = new OleDbDataAdapter(sql, connection);
                oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
                oledbAdapter.Fill(ds);
                this.dataGridView1.DataSource = ds.Tables[0];

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }

       
  
    }
}
